package com.jacksonling.mapper;

import com.jacksonling.pojo.ClazzCountOption;
import com.jacksonling.pojo.PageResult;
import com.jacksonling.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {


    /**
     * 分页查询（学员列标查询）
     */
    List<Student> list(String name, Integer degree, Integer clazzId);

    /**
     * 新增学生
     */
    @Insert("insert into student(name, no, gender, phone,id_card, is_college, address, degree, graduation_date,clazz_id, create_time, update_time)"
            + " VALUES "
            + "( #{name},#{no},#{gender},#{phone},#{idCard}," +
            "#{isCollege},#{address},#{degree}," + "#{graduationDate},"
            + "#{clazzId},#{createTime},#{updateTime})")
    void insert(Student student);

    /**
     * 根据 ID 查询学生
     */
    @Select("select * from student where id = #{id};")
    Student getById(Integer id);

    /**
     * 修改学生信息
     */
    void update(Student student);

    /**
     * 批量删除学生
     */
    void deleteBatch(List<Integer> ids);

    /**
     * 学生违纪处理
     */
    @Update("update student set violation_count = violation_count + 1," +
            "violation_score = violation_score + #{score} " +
            "where id = #{id}")
    void updateViolation(Integer id, Short score);

    /**
     * 班级人数统计
     */
    @Select("select c.name cname , count(s.id) scount from clazz c  left join student s on s.clazz_id = c.id group by c.name order by count(s.id) desc ")
    List<Map<String,Object>> getStudentCount();

    /**
     * 统计学员学历
     */
    @MapKey("name")
    List<Map> countStudentDegreeData();

    /**
     * 统计每个班级学员人数
     */
    @Select("select count(*) from student where clazz_id = #{id}")
    Integer countByClazzId(Integer id);

}
